package com.treasure.common.model;

import com.treasure.common.utils.RandomIdGenerator;

/**
 * @author sunhongmin
 * @date 2023/9/1 17:44
 * @description
 */
public class TraceIdHolder {

    private static final ThreadLocal<String> traceIdCache = new InheritableThreadLocal<>();

    public static String getTraceId() {
        return traceIdCache.get();
    }

    public static void setTraceId(String traceId) {
        traceIdCache.set(traceId);
    }

    public static void clear() {
        traceIdCache.remove();
    }

    /**
     * 获得12个长度的十六进制的UUID
     * @return UUID
     */
    public static String genTraceId() {
        return RandomIdGenerator.traceId();
    }
}
